package com.zzj.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zzj.annotation.CommentCountAnnotation;
import com.zzj.annotation.LogAnnotation;
import com.zzj.base.Result;
import com.zzj.entity.Reply;
import com.zzj.model.dto.comment.ReplyCreateDto;
import com.zzj.service.IReplyService;
import jakarta.annotation.Resource;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 回复表 前端控制器
 * </p>
 *
 * @author zzj
 * @since 2023-07-17
 */
@RestController
@RequestMapping("/reply")
public class ReplyController {


    @Resource
    private IReplyService replyService;

    @LogAnnotation(name = "添加回复", description = "新增回复")
    @Transactional
    @PostMapping("createPostReply")
    @CommentCountAnnotation
    public Result<?> createPostComment(@RequestBody @Validated ReplyCreateDto in) {
        Reply reply = JSONObject.parseObject(JSON.toJSONString(in), Reply.class);
        replyService.save(reply);
        return Result.success("回复成功");
    }

}
